import request from "@/utils/service"

// 添加分类
export const addCategoryAPI = (data: any) => {
  return request.post<any, any>("/category", data)
}

// 获取分类列表
export const getCategoryListAPI = ({
  page,
  pageSize,
  name,
  type
}: {
  page: number
  pageSize: number
  name?: string
  type?: number
}) => {
  if (type && name) {
    return request.get<any, any>(`/category/page?page=${page}&pageSize=${pageSize}&type=${type}&name=${name}`)
  } else if (type) {
    return request.get<any, any>(`/category/page?page=${page}&pageSize=${pageSize}&type=${type}`)
  } else if (name) {
    return request.get<any, any>(`/category/page?page=${page}&pageSize=${pageSize}&name=${name}`)
  } else {
    return request.get<any, any>(`/category/page?page=${page}&pageSize=${pageSize}`)
  }
}

// 分类状态切换
export const changeCategoryStatusAPI = (id: number, status: number) => {
  return request.post<any, any>(`/category/status/${status}?id=${id}`)
}

// 删除分类
export const deleteCategoryAPI = (id: number) => {
  return request.delete<any, any>(`/category?id=${id}`)
}

// 修改分类
export const updateCategoryAPI = (data: any) => {
  return request.put<any, any>(`/category`, data)
}

// 获取分类列表
export const getCategoryListAllAPI = (type: number) => {
  return request.get<any, any>(`/category/list?type=${type}`)
}
